package com.example.common;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class HttpStatusDescriptionsImpl implements HttpStatusDescriptions {

    private final Map<Integer, String> statusDescriptions;

    public HttpStatusDescriptionsImpl() {
        statusDescriptions = new HashMap<>();
        statusDescriptions.put(200, "操作成功!");
        statusDescriptions.put(-1, "操作失败!");
        statusDescriptions.put(302, "信息认证失败,请重新登录.");
        statusDescriptions.put(404, "资源不存在");
        statusDescriptions.put(401, "认证失败, 权限不足!");
        statusDescriptions.put(403, "授权失败, 权限不足!");

    }

    @Override
    public String getDescription(int statusCode) {
        // 如果找不到对应的描述信息，则返回一个默认的描述信息
        return statusDescriptions.getOrDefault(statusCode, "Unknown status code: " + statusCode);
    }
}